<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.fckeditor.net" prefix="FCK" %>       
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>淘宝商品</title>
<%@ include file="/common/include.jsp"%>
<link href="/summer/template/admin/css/input.css" rel="stylesheet"
	type="text/css" />
<link href="/summer/template/admin/css/input.css" rel="stylesheet" type="text/css" />
<meta name="Author" content="SHOP++ Team" />
<meta name="Copyright" content="SUMMER" />
<link rel="icon" href="favicon.ico" type="image/x-icon" />
<script type="text/javascript">



var begin="";
var title="";

function init()
{
	var $popValue = $("input[name='taoBaoGood.popvalue']");
	$('#table2').hide(); 
	
	begin=$popValue.val();
	
	getVoucherGroupData();
	//begin="";
	

}

function getVoucherGroupData(vv,pid,keyProp){

//alert(begin);
	
	var $popValue = $("input[name='taoBaoGood.popvalue']");
	var url="tao_bao_good!getPop.action?cid=${taoBaoGood.category}";

	
	//alert($popValue.val());
	var pops=begin.split(";"); //初始值

	  // alert(pops[2]);
	if(pid!=null)
	{
	//alert(pid);
		if($('div[class^='+pid+']').size()>1)
		{
		//	$('select[class='+pid+']').remove();
			
			//alert(($('div[class^='+pid+']').not('[class='+pid+']')).size());
			    $('div[class^='+pid+']').not('[class='+pid+']').remove();
				//alert($('div[class^='+pid+']').next().attr("class"));
			 //$('div[class^='+pid+']').next().remove();
		}
	}
	if(vv!=null&&keyProp)
	{
		url+="&child_path="+vv; //传入下一个的 child_path
	}
	else if(vv!=null&&keyProp==false)
	{
		url+="&bind="+vv; //传入下一个的 child_path
	}
	var $abcd = $(".abcd");
	$.ajax({
	    type: "Post",
	    url: url,
	    dataType: "json",
	    data: "",
	    cache: true,
	    async:true,
	    success: function(res) {
	            for(var j =0;j < res.length; j++)
	            {
		            
		            var selecthtml="";
	            	var selectClass= res[j].selectClass;
	            	var product_id= res[j].product_id;
	            	var keyProp= res[j].keyProp;
	            	var pid=res[j].pid;
	            	var str = $("<select  onchange='getVoucherGroupData(this.value,\""+selectClass+"\","+keyProp+")'></select>");
	 	            var option = "";
	                var name= res[j].name;
	               
	               var pop=res[j].pop;
	               var parent_path=res[j].parent_path;
	               var binds_str=res[j].binds_str;
	               var binds=res[j].binds;
	               var bind=res[j].bind;
	               var desc=res[j].desc;

	              
	               if(pop!=null)
	               {
	               option += "<option value=\"0\">请选择</option>";
	                for(var i =0;i < pop.length; i++)
		            {
	                	option += "<option " ;
	                	
			            for(var k=0;k<pops.length-1;k++)
			            {
				   
				     
							if(pops[k]==(pid+":"+pop[i].vid))
							{
								option+=" selected=\"selected\" ";
								//判断是否parent

								//if(pop[i].isParent==true)
							//	{
									getVoucherGroupData(parent_path+pid+":"+pop[i].vid+";",null,keyProp);
								//}
								
							}
				         }
				      
	                	 option += "value=\""+parent_path+pid+":"+pop[i].vid +";"+ "\">" + pop[i].name + "</option>";
		            }
		        	
	                selecthtml+=name+":"+$(str).html(option).parent().html()+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	               }
	               if(selecthtml!="")
	  	         {
	  	  	         
	  	            $abcd.before("<div class='"+selectClass+"'>"+selecthtml+"</div>");
	  	         }

	            
	            }
	         
	            
	         if(pop==null)
				{
	        	 $popValue.val(parent_path+binds);
	        	 if(product_id!=null)
	        	 {
	        	 $("input[name='taoBaoGood.product_id']").val(product_id);
	        	 }
		        	// $("input[name='taoBaoGood.description']").val(desc);
				}
	         else
	         {
	        //	 alert( parent_path);
	        	 $popValue.val(parent_path);
	       
	         }
		 
	            
	        
	    }
	
	});
}

function check()
{
//判断select 是否有空选择
	
	
var $popValue = $("input[name='taoBaoGood.popvalue']");

var $selects =$("select");


for(var i=0;i<$selects.size();i++)
{
	if(i<=1)
		{
		title+=$selects[i].options[$selects[i].selectedIndex].text+" ";
		}
	if($selects[i].value=="0")
	{
		alert("您还有为选择的属性");
		return false;
	}
}


if($popValue.val().split(";").length<$selects.size())
	{
	
	//alert($popValue.val()); 	alert(pops);
 var pops="";
	for(var i=0;i<$selects.size();i++)
	{
		pops=inOne(pops,$selects[i].options[$selects[i].selectedIndex].value)

		
	}
	$popValue.val(pops);

	}
else
{
	//alert($popValue.val());
}


var titleValue = $("input[name='taoBaoGood.title']").val();
title="["+title.replace(/(\s*$)/g,"")+"]"+titleValue.substr(titleValue.indexOf("]")+1);

$("input[name='taoBaoGood.title']").val(title);


}


function inOne(total,sub)
{

	if(total==null||total=="")
	{
		total=sub;
	}
	else
	{
		
		var subArray=sub.split(";");

		for(var i=0;i<subArray.length;i++)
		{
			if(total.indexOf(subArray[i])==-1)
			{
				total+=subArray[i]+";";
			}

		}
	}
	

	return total;
}

function tab(a)
{
if(a=="2")
{
	
	$('#table2').show();
	$('#table1').hide();
}
else
{
	$('#table1').show();
	$('#table2').hide();
}

}

</script>


</head>

 
<body class="input" onload="init()">


	<div class="body">
				<div class="inputBar">
			<h1><span class="icon">&nbsp;</span>
			<s:if test="id==null">添加淘宝商品 </s:if><s:else>编辑淘宝商品</s:else>
			</h1>
		</div>

		<form id="inputForm" class="validate" action="<s:if test="id==null">tao_bao_good!save.action</s:if><s:else>tao_bao_good!update.action</s:else>" method="post">
			<input type="hidden" name="redirectionUrl" value="tao_bao_good!list.action" />
			<input type="hidden" name="goods.id" value="${id}" />
			<input type="hidden" name="taoBaoGood.product_id" value="${taoBaoGood.product_id}" />
			<input type="hidden" name="taoBaoGood.vedios" value="${taoBaoGood.vedios}" />
			<input type="hidden" name="taoBaoGood.postId" value="${taoBaoGood.postId}" />
			<input type="hidden" name="taoBaoGood.pic_status" value="${taoBaoGood.pic_status}" />
			<input type="hidden" name="taoBaoGood.fromUrl" value="${taoBaoGood.fromUrl}" />
			<div class="blank"></div>
			<ul class="tab">
				<li>
					<input type="button" value="基本信息" hidefocus="true" onclick="tab(1)" />
				</li>
				<li>
					<input type="button" value="详细资料" hidefocus="true" onclick="tab(2)"/>
				</li>
			
			</ul>
			<table id="table1"  class="inputTable tabContent">
					
					<s:if test="id==null">
							<input type="hidden" name="taoBaoGood.id" class="" />
							<label class="requireField">*</label>
					</s:if><s:else>
							<input type="hidden" class="formText" name="taoBaoGood.id" value="<s:property value='taoBaoGood.id' />" />  
						</s:else>
					<tr>
					<th>
					宝贝名称	:
					</th>
					<td>
					<s:if test="id==null">
							<input type="text" name="taoBaoGood.title" class="" />
							<label class="requireField">*</label>
					</s:if><s:else>
							<input type="text" class="formText" name="taoBaoGood.title" value="<s:property value='taoBaoGood.title' />" />  
						</s:else>
					</td>
				</tr>
				
					<tr>
					<th>
					宝贝类目	:
					</th>
					<td>
					<s:if test="id==null">
							<input type="text" name="taoBaoGood.category" class="" />
							<label class="requireField">*</label>
					</s:if><s:else>
							<input type="text" class="formText" name="taoBaoGood.category" value="<s:property value='taoBaoGood.category' />" />  
						</s:else>
					</td>
				</tr>
				
					<tr>
					<th>
					商店类目	:
					</th>
					<td>
					<s:if test="id==null">
							<input type="text" name="taoBaoGood.shopCategoryId" class="" />
							<label class="requireField">*</label>
					</s:if><s:else>
							<input type="text" class="formText" name="taoBaoGood.shopCategoryId" value="<s:property value='taoBaoGood.shopCategoryId' />" />  
						</s:else>
					</td>
				</tr>
				
					<tr>
					<th>
					省份	:
					</th>
					<td>
					<s:if test="id==null">
							<input type="text" name="taoBaoGood.prov" class="" />
							<label class="requireField">*</label>
					</s:if><s:else>
							<input type="text" class="formText" name="taoBaoGood.prov" value="<s:property value='taoBaoGood.prov' />" />  
						</s:else>
					</td>
				</tr>
				
					<tr>
					<th>
					城市	:
					</th>
					<td>
					<s:if test="id==null">
							<input type="text" name="taoBaoGood.city" class="" />
							<label class="requireField">*</label>
					</s:if><s:else>
							<input type="text" class="formText" name="taoBaoGood.city" value="<s:property value='taoBaoGood.city' />" />  
						</s:else>
					</td>
				</tr>
				
					<tr>
					<th>
					销售价格	:
					</th>
					<td>
					<s:if test="id==null">
							<input type="text" name="taoBaoGood.price" class="" />
							<label class="requireField">*</label>
					</s:if><s:else>
							<input type="text" class="formText" name="taoBaoGood.price" value="<s:property value='taoBaoGood.price' />" />  
						</s:else>
					</td>
				</tr>
				
					<tr>
					<th>
					数量	:
					</th>
					<td>
					<s:if test="id==null">
							<input type="text" name="taoBaoGood.quantity" class="" />
							<label class="requireField">*</label>
					</s:if><s:else>
							<input type="text" class="formText" name="taoBaoGood.quantity" value="<s:property value='taoBaoGood.quantity' />" />  
						</s:else>
					</td>
				</tr>
				
					<tr>
					<th>
						有效期:
					</th>
					<td>
					<s:if test="id==null">
							<input type="text" name="taoBaoGood.duration" class="" />
							<label class="requireField">*</label>
					</s:if><s:else>
							<input type="text" class="formText" name="taoBaoGood.duration" value="<s:property value='taoBaoGood.duration' />" />  
						</s:else>
					</td>
				</tr>

				
					<tr>
					<th>
					自动重发	:
					</th>
					<td>
					<s:if test="id==null">
							<input type="text" name="taoBaoGood.autoRepost" class="" />
							<label class="requireField">*</label>
					</s:if><s:else>
							<input type="text" class="formText" name="taoBaoGood.autoRepost" value="<s:property value='taoBaoGood.autoRepost' />" />  
						</s:else>
					</td>
				</tr>
					<tr>
					<th>
					橱窗推荐	:
					</th>
					<td>
					<s:if test="id==null">
							<input type="text" name="taoBaoGood.shopWindow" class="" />
							<label class="requireField">*</label>
					</s:if><s:else>
							<input type="text" class="formText" name="taoBaoGood.shopWindow" value="<s:property value='taoBaoGood.shopWindow' />" />  
						</s:else>
					</td>
				</tr>
				
				
					<tr>
					<th>
					宝贝图片	:
					</th>
					<td>
					<s:if test="id==null">
							<input type="text" name="taoBaoGood.pic" class="" />
							<label class="requireField">*</label>
					</s:if><s:else>
							<input type="text" class="formText" name="taoBaoGood.pic" value="<s:property value='taoBaoGood.pic' />" />  
						</s:else>
					</td>
				</tr>
				
					<tr>
					<th>
					必要属性	:
					</th>
					<td>
					<s:if test="id==null">
							<div class="abcd"></div>
							<input type="hidden" name="taoBaoGood.popvalue" />
							<label class="requireField">*</label>
					</s:if><s:else>
							<div class="abcd"></div>
							<input type="hidden"  name="taoBaoGood.popvalue" value="${taoBaoGood.popvalue}" /> 
							
							
						</s:else>
					</td>
				</tr>
					<tr>
					<th>
					属性关键字:
					</th>
					<td>
					<s:if test="id==null">
							<input type="text" name="taoBaoGood.newPic" class="" />
							<label class="requireField">*</label>
					</s:if><s:else>
							<input type="text" class="formText" name="taoBaoGood.newPic" value="<s:property value='taoBaoGood.newPic' />" />  
						</s:else>
					</td>
				</tr>
					
			</table>
			
				<table id="table2" class="inputTable tabContent" >
					<tr>
					<td colspan="2">
					<s:if test="id==null">
							 <textarea class="wysiwyg"  style="width: 100%; height: 450px;" name="taoBaoGood.description" /></textarea>
							<label class="requireField">*</label>
					</s:if><s:else>
					<FCK:editor instanceName="taoBaoGood.description" value="${taoBaoGood.description}" width="100%" height="700"> </FCK:editor> 
						</s:else>
					</td>
				</tr>
				</table>
			
			<div class="buttonArea">
				<input type="submit" class="formButton"  value="确  定" onclick="return check()" hidefocus="true" />&nbsp;&nbsp;&nbsp;&nbsp;
				<input type="button" class="formButton" onclick="window.history.back(); return false;" value="返  回" hidefocus="true" />
			</div>
		</form>
	</div>
</body>
</html>